<template>
  <div>
    <div class="loading-box" v-if="isLoading">
      <loading></loading>
    </div>
    <div class="contents" v-else>
      <ad-item
        v-for="(item, index) in ads"
        :key="index"
        :data="item"
        @click.native="skip(item)"
        >
      </ad-item>
      <div class="button-box">
        <button class="button is-big" @click="toList">查看更多贷款</button>
      </div>
    </div>
  </div>
</template>
<script>
import AdItem from '@/components/AdItem'
import { mapGetters } from 'vuex'
export default {
  name: 'category',
  components: {
    AdItem
  },
  computed: {
    ...mapGetters({
      info: 'global/info',
      isIos: 'isIos'
    })
  },
  created () {
    this.isLoading = true
    this.$api.get(`ads/ad_item/${this.$route.params.id}`).then(req => {
      this.ads = req.data
      this.isLoading = false
    })
  },
  data () {
    return {
      isLoading: false,
      ads: []
    }
  },
  methods: {
    toList () {
      if (this.info.source_app.indexOf('com.') === -1) { // 若不在app里则直接跳转
        this.$router.push('/list')
      } else {
        try {
          if (this.isIos) { // 判断是否是IOS
            window.sendEvent()
          } else {
            alert('sendEvent')
          }
        } catch (e) {}
      }
    },
    skip (item) {
      this.$router.push({ name: 'Detail', params: { id: item.app_store_id } })
    }
  }
}
</script>
<style lang="scss" scoped>
.contents{
  padding-top: 10px;
}
</style>

